/*
* Created by: yyf
* Description: 基金管理--拟设立基金详情页
*/
<template>
    <div>
        <div class="right">
            <!--头部组件-->
            <csEstablishingFundHeadDetail></csEstablishingFundHeadDetail>
            <!--节点-->
            <csNode v-model="fundOthNode"></csNode>
            <el-tabs type="border-card"
                     class="ca-m-t-15 ca-tabs" @tab-click="selectTab" :value="tabIndex">
                <el-tab-pane label="基金详情">
                    <csRedDot slot="label" label="基金详情" :showDot="dotStateList[0]"></csRedDot>
                    <div v-if="tabIndex == 0">
                        <csEstablishingFundDetails @addRedDot="addRedDot"></csEstablishingFundDetails>
                    </div>
                </el-tab-pane>
                <el-tab-pane :disabled="!isAuthFileSee" label="基金文件">
                    <csRedDot slot="label" label="基金文件" :showDot="dotStateList[1]"></csRedDot>
                    <div v-if="tabIndex == 1">
                        <csEstablishingFundFileDetail
                            title="基金文件："
                            :businessId="itemId"
                            :fileType="fileType"
                            :addAuth="pageName"
                            @addDot="addRedDot(1)">
                        </csEstablishingFundFileDetail>
                    </div>
                </el-tab-pane>
                <el-tab-pane :disabled="!isAuthPartnerSee">
                    <csRedDot slot="label" label="基金合伙人" :showDot="dotStateList[2]"></csRedDot>
                    <div v-if="tabIndex == 2">
                        <csEstablishingFundPartnerDetail @addRedDot="addRedDot"></csEstablishingFundPartnerDetail>
                    </div>
                </el-tab-pane>
            </el-tabs>
        </div>
    </div>
</template>

<script type="text/ecmascript-6">
    import { addRemind } from '__service/utils';
    import { getDetailRemind, read } from '__service/utils';
    import { isNoAuth } from '__service/utils';
    export default {
        data() {
            return {
                itemId: this.$route.params.itemId, // 基金id
                tabIndex: this.$route.params.tabIndex.toString(),
                fundOthNode: this.$store.state.user.dictionaryMap.fundOthNode, // 基金节点名称
                fileType: '', // 基金文件类型
                dotStateList: [false, false, false], // 小红点状态
                isAuthFileSee: isNoAuth('拟设立基金-基金文件-查看'),
                isAuthPartnerSee: isNoAuth('拟设立基金-合伙人信息-查看'),
                pageName: '拟设立基金-基金文件-编辑'
            }
        },
        watch: {
        },
        props: {},
        mounted() {
            let fileTypeList = this.$store.state.user.fileFloderDicVoList;
            fileTypeList.map(item=>{
                if (item.name === '基金文件') {
                    this.fileType = item.type;
                }
            })
            // 获取tab index
            this.tabIndex = this.$route.params.tabIndex;
            // 获取红点
            this.getDotList();
            // 为子组件创建的第三方组件方法
            this.$root.Dot.$on('getDotList', () => {
                this.getDotList()
            })
        },
        methods: {
            async addRedDot(index) {
                // 添加小红点
                await addRemind({
                    dataId: this.$route.params.itemId, // 业务id
                    dataTab: index, // tab页顺序 head 也为0 新建为'-1'
                    dataType: 4, // 1拟投资项目,2已投资项目,3母基金,4拟设立基金,5已设立基金,6客户,7潜在项目
                });
                // 根据第三方组件来调用 父组件中定义的方法 重新获取小红点
                this.$root.Dot.$emit('getDotList');
                // 添加小红点 end
            },
            // 选项卡选择
            selectTab(tab) {
                this.tabIndex = tab.index;
                // 去除小红点
                read({ dataId: this.$route.params.itemId, dataTab: this.tabIndex, dataType: 4 });
                this.dotStateList[this.tabIndex] = false;
                this.dotStateList = this.dotStateList.concat([]);
            },
            // 设置小红点
            async getDotList() {
                // 获取小红点
                const dotList = await getDetailRemind({ dataId: this.$route.params.itemId, dataType: 4 });
                dotList.map(x => {
                    this.dotStateList[x.dataTab] = true;
                });
                this.dotStateList = this.dotStateList.concat([]);
            },
        },
        components: {
            'csEstablishingFundHeadDetail': require('./header/index'), // 头部详情
            'csEstablishingFundDetails': require('./fund-details/index'), // 基金详情
            'csEstablishingFundFileDetail': require('__components/file-list/index'), // 基金文件详情
            'csEstablishingFundPartnerDetail': require('./fund-partner/index'), // 基金合伙人详情
            'csNode': require('__components/project-node/index'),  // 项目信息 - 项目节点
            'csRedDot': require('__components/red-dot'), // 选项卡小红点
        },
    }
</script>
<style rel="stylesheet/scss" lang="scss" scoped>
</style>
